package com.desire.test;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.io.IOException;

/**
 * @author desire
 */
public class _24_commonsio文件操作 {
    public static void main(String[] args) throws IOException {
        // 创建文件
        FileUtils.write(new File("C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\comm.txt"), "hello大家好", "utf-8", true);
        //读取 文件
        String txt = FileUtils.readFileToString(new File("C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\comm.txt"), "utf-8");
        System.out.println(txt);

        String fn = "C:\\Users\\desire\\Desktop\\javaProject\\01-javaBase\\src\\main\\resources\\comm.txt";
        System.out.println(FilenameUtils.getExtension(fn));
        System.out.println(FilenameUtils.getName(fn));
        System.out.println(FilenameUtils.getBaseName(fn));
        System.out.println(FilenameUtils.getFullPathNoEndSeparator(fn));
        //删除文件 //
        FileUtils.delete(new File("p10_40(180_120).jpg"));
        FileUtils.deleteDirectory(new File("c:\\abc4"));
        //apache commons io 工具类实现目录的复制
        FileUtils.copyDirectory(new File("c:\\abc5"), new File("c:\\ddd6"));
    }

}
